/*
 * @Description: 
 * @Author: zyj
 * @Date: 2022-05-27 17:12:16
 * @LastEditors: zyj
 * @LastEditTime: 2022-05-27 17:12:25
 */
/* 函数组合 */
function sum(a, b) {
  return a + b;
}
function toUpper(str) {
  return str.toUpperCase();
}
function add(str) {
  return "***" + str + "***";
}


//期望实现add(toUpper(sum('张三','前端开发')))的效果


function compose(...fns) {
  return function (...args) {
    let firstFn = fns.pop();
    fns.reduce((a, b) => {
      return b(a);
    }, firstFn(...args));
  }
}


compose(add, toUpper, sum)('张三', 15)